package com.example.showlistexample;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class InfoAdapter extends RecyclerView.Adapter<InfoAdapter.ViewHolder> {
    private List<InfoBean> mList;

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView name;
        TextView tvCharacter;
        TextView tvDec;
        TextView tvPrice;
        ImageView url;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tv_title);
            tvCharacter = itemView.findViewById(R.id.tv_character);
            tvDec = itemView.findViewById(R.id.tv_dec);
            tvPrice = itemView.findViewById(R.id.tv_price);
            url = itemView.findViewById(R.id.iv_image);
        }

    }

    public InfoAdapter(List<InfoBean> list) {
        mList = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_info, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        InfoBean infoBean = mList.get(position);
        holder.name.setText(infoBean.getName());
        holder.tvCharacter.setText(infoBean.getCharacter());
        holder.tvDec.setText(infoBean.getDec());
        holder.tvPrice.setText(infoBean.getPrice());
        holder.url.setImageResource(infoBean.getUrl());
    }


    @Override
    public int getItemCount() {
        return mList.size();
    }
}
